﻿using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework.AppContainer;
using UnitTestWinRTConverters.ObjectsTestBase;
using WinRTConverters.Visibility;
using Windows.UI.Xaml;
using Assert = Microsoft.VisualStudio.TestPlatform.UnitTestFramework.Assert;

namespace UnitTestWinRTConverters
{
    [TestClass]
    public class VisibilityConvertersUnitTest
    {
        [UITestMethod]
        public void BooleanToVisibilityConverterTest()
        {
            //Classique
            var objectTest = new UIGridVisibilityTest(new BooleanToVisibilityConverter(), true);
            Assert.AreEqual(Visibility.Visible, objectTest.ConvertValue);

            objectTest.SourceValue = false;
            Assert.AreEqual(Visibility.Collapsed, objectTest.ConvertValue);

            //Mode inversé
            var objectTestInvert = new UIGridVisibilityTest(new BooleanToVisibilityConverter(), true, true);
            Assert.AreEqual(Visibility.Collapsed, objectTestInvert.ConvertValue);

            objectTestInvert.SourceValue = false;
            Assert.AreEqual(Visibility.Visible, objectTestInvert.ConvertValue);
        }

        [UITestMethod]
        public void InvertVisibilityConverterTest()
        {
            var objectTest = new UIGridVisibilityTest(new InvertVisibilityConverter(), Visibility.Visible);
            Assert.AreEqual(Visibility.Collapsed, objectTest.ConvertValue);

            objectTest.SourceValue = Visibility.Collapsed;
            Assert.AreEqual(Visibility.Visible, objectTest.ConvertValue);
        }

        [UITestMethod]
        public void ValueNotEqualNullToVisibilityConverterTest()
        {
            //Classique
            var objectTest = new UIGridVisibilityTest(new ValueNotEqualNullToVisibilityConverter(), null);
            Assert.AreEqual(Visibility.Collapsed, objectTest.ConvertValue);

            objectTest.SourceValue = new object();
            Assert.AreEqual(Visibility.Visible, objectTest.ConvertValue);

            //Mode inversé
            var objectTestInvert = new UIGridVisibilityTest(new ValueNotEqualNullToVisibilityConverter(), null, true);
            Assert.AreEqual(Visibility.Visible, objectTestInvert.ConvertValue);

            objectTestInvert.SourceValue = new object();
            Assert.AreEqual(Visibility.Collapsed, objectTestInvert.ConvertValue);
        }

        [UITestMethod]
        public void VisibilityGreaterThanCountConverterTest()
        {
            //50 > 0 => Visible
            var objectTest = new UIGridVisibilityTest(new VisibilityGreaterThanCountConverter(), 50);
            Assert.AreEqual(Visibility.Visible, objectTest.ConvertValue);

            //50 > 80 => Collapsed
            var objectTestParameter = new UIGridVisibilityTest(new VisibilityGreaterThanCountConverter(), 50, 80);
            Assert.AreEqual(Visibility.Collapsed, objectTestParameter.ConvertValue);
        }

        [UITestMethod]
        public void StringNotEqualNullOrEmptyToVisibilityConverterTest()
        {
            //Classique
            var objectTest = new UIGridVisibilityTest(new StringNotEqualNullOrEmptyToVisibilityConverter(), "");
            Assert.AreEqual(Visibility.Collapsed, objectTest.ConvertValue);

            objectTest.SourceValue = "Test";
            Assert.AreEqual(Visibility.Visible, objectTest.ConvertValue);

            //Mode inversé
            var objectTestInvert = new UIGridVisibilityTest(new StringNotEqualNullOrEmptyToVisibilityConverter(), "", true);
            Assert.AreEqual(Visibility.Visible, objectTestInvert.ConvertValue);

            objectTestInvert.SourceValue = "Test";
            Assert.AreEqual(Visibility.Collapsed, objectTestInvert.ConvertValue);
        }
    }
}
